#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
using namespace std;

const int N = 1e6 + 10;

int main() {
    vector<int> arr;
    int n, p;
    cin >> n >> p;
    for (int i = 0; i < n; i++)
    {
        int k;
        cin >> k;
        arr.push_back(k);
    }
    sort(arr.begin(), arr.end());
    int left = 0;
    int right = 0;
    int sum = 0;
    while (right < n)
    {
        while (arr[right] - arr[left] > 2 * p)
        {
            left++;
        }
        sum = max(right - left + 1, sum);
        right++;
    }
    cout << sum << endl;
    return 0;
}
string str;

bool reserve(int left, int right, int n)
{
    int sum = 0;
    if (str[left] != str[right] || left < 0)
    {
        return false;
    }
    return true;
}

int main() {
    cin >> str;
    int n = str.size();
    int ret = -1;
    for (int i = 0; i < n - 1; i++)
    {
        if (reserve(i, i + 1, n))
        {
            ret = 2;
            break;
        }
        if (reserve(i - 1, i + 1, n))
        {
            ret = 3;
        }
    }
    cout << ret << endl;
    return 0;
}

int main() {
    int n;
    cin >> n;
    int arr[100010] = { 0 };
    long long hash[100010] = { 0 };
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }
    hash[1] = arr[1];
    for (int i = 2; i <= n; i++)
    {
        hash[i] = max(hash[i - 1], hash[i - 2] + arr[i]);
    }
    cout << hash[n] << endl;
    return 0;
}

int main() {
    int n;
    cin >> n;
    int arr[100010] = { 0 };
    long long g[100010] = { 0 };
    long long f[100010] = { 0 };
    for (int i = 1; i <= n; i++)
    {
        cin >> arr[i];
    }
    for (int i = 1; i <= n; i++)
    {
        f[i] = g[i - 1] + arr[i];
        g[i] = max(g[i - 1], f[i - 1]);
    }
    cout << max(g[n], f[n]) << endl;
    return 0;
}

#include <functional>
#include <queue>
class Solution {
public:
    struct cmp
    {
        bool operator()(vector<int> x1, vector<int> x2)
        {
            return x1[0] < x2[0];
        }
    }cmp;

    int minmumNumberOfHost(int n, vector<vector<int> >& startEnd) {
        // write code here
        sort(startEnd.begin(), startEnd.end(), cmp);
        priority_queue<int, vector<int>, greater<int>> q;
        for (int i = 0; i < n; i++)
        {
            if (q.empty())
            {
                q.push(startEnd[i][1]);
            }
            else
            {
                if (q.top() <= startEnd[i][0])
                {
                    q.pop();
                    q.push(startEnd[i][1]);
                }
                else
                {
                    q.push(startEnd[i][1]);
                }
            }
        }
        return q.size();
    }
};


class Solution {
public:
    struct cmp
    {
        bool operator()(vector<int> x1, vector<int> x2)
        {
            return x1[0] < x2[0];
        }
    }cmp;

    int minmumNumberOfHost(int n, vector<vector<int> >& startEnd) {
        // write code here
        sort(startEnd.begin(), startEnd.end(), cmp);
        vector<int> ret;
        for (int i = 0; i < n; i++)
        {
            if (ret.empty())
            {
                ret.push_back(startEnd[i][1]);
            }
            else
            {
                int k = 1;
                for (int j = 0; j < ret.size(); j++)
                {
                    if (startEnd[i][0] >= ret[j])
                    {
                        ret[j] = startEnd[i][1];
                        k = 0;
                        break;
                    }
                }
                if (k)
                {
                    ret.push_back(startEnd[i][1]);
                }
            }
        }
        return ret.size();
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    int sum = n;
    while (--m)
    {
        sum *= (n - 1);
        sum %= 109;
    }
    cout << sum << endl;
    return 0;
}




int n, m;
int x1, x2, y1, y2;
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
int dp[1010][1010];
char board[1010][1010];

int dfs()
{
    memset(dp, -1, sizeof(dp));
    if (board[x2][y2] == '*')
    {
        return -1;
    }
    queue<pair<int, int>> q;
    q.push({ x1,y1 });
    dp[x1][y1] = 0;
    while (!q.empty())
    {
        auto [a, b] = q.front();
        q.pop();
        for (int i = 0; i < 4; i++)
        {
            int x = a + dx[i];
            int y = b + dy[i];
            if (x >= 1 && x <= n && y >= 1 && y <= m && board[x][y] == '.' && dp[x][y] == -1)
            {
                q.push({ x,y });
                dp[x][y] = dp[a][b] + 1;
                if (x == x2 && y == y2)
                {
                    return dp[x2][y2];
                }
            }
        }
    }
    return -1;
}

int main() {
    cin >> n >> m >> x1 >> y1 >> x2 >> y2;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> board[i][j];
        }
    }
    cout << dfs() << endl;
    return 0;
}